﻿
namespace Mulala.Cavan.Presentation.Mvc.Controller
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Mulala.Cavan.Presentation.Seedwork;
    using Mulala.Cavan.Domain.MainBoundedContext.NannyModule;
    using Mulala.Cavan.Domain.MainBoundedContext.SearchModule;
    using Mulala.Cavan.Presentation.Mvc.ViewModel;
    using Mulala.Cavan.Application.MainBoundedContext.NannyModule;
    using System.Web.Mvc;
    using Mulala.Cavan.Domain.MainBoundedContext.Setting;
    using Mulala.Cavan.Application.MainBoundedContext.AttachmentModule;

    public class NannyCommentController : EntityController<NannyComment, NannyCommentSearch, INannyCommentViewModel, INannyCommentAppService>, INannyCommentController
    {
        private IAttachmentAppService AttachmentAppService { get; set; }

        public override string ControllerName
        {
            get { return "NannyComment"; }
        }

        public override bool UseDenied
        {
            get { return false; }
        }

        [ActionName("topcomment")]
        [ChildActionOnly]
        public ActionResult GetNannyComments(int id)
        {
            IDictionary<string, bool> orderBy = new Dictionary<string, bool>();
            orderBy.Add("CreateTime", true);

            NannyCommentSearch nannyCommentSearch = NannyCommentSearchFactory.CreateNannyCommentSearch(id, orderBy, 1, Project.Settings.TopNannyCommentAmount);

            long total = 0;
            IList<NannyComment> nannyComments = this.AppService.GetBySearch(nannyCommentSearch, out total).ToList();
            INannyCommentsViewModel nannyCommentsViewModel = ModelFactory.CreateModel<INannyCommentsViewModel>();
            IList<INannyCommentViewModel> nannyCommentViewModels = NannyCommentViewModelConverter.Convert(nannyComments);
            nannyCommentsViewModel.NannyComments = nannyCommentViewModels;

            return PartialView("~/Views/NannyComment/_nannyCommentPartial.cshtml", nannyCommentsViewModel);
        }


    }
}
